package cn.tansanqinger.dao.sql.topic;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.tansanqinger.dao.sql.ICollectTopicSqlDao;
import cn.tansanqinger.pojo.Collecttopic;

@Repository
public class CollectTopicSqlDaoImpl {

	@Autowired
	private ICollectTopicSqlDao dao;
	
	/**
	 * 查询数据，通过条件查询
	 * @param id
	 * @param page
	 * @return
	 */
	public List<Collecttopic> selectMessage(int id, int page){
		QueryWrapper<Collecttopic> queryWrapper = new QueryWrapper<Collecttopic>();
		queryWrapper.lambda().eq(Collecttopic::getUid, id);
		Page<Collecttopic> pg = new Page<Collecttopic>(page, 10);
		IPage<Collecttopic> iPage = dao.selectPage(pg, queryWrapper);
		return iPage.getRecords();
	}
	
	/**
	 * 返回该用户数据条数
	 * @param id
	 * @return
	 */
	public int numberMessage(int id) {
		QueryWrapper<Collecttopic> queryWrapper = new QueryWrapper<Collecttopic>();
		queryWrapper.lambda().eq(Collecttopic::getUid, id);
		return dao.selectCount(queryWrapper);
	}
		
	/**
	 * 查询数据
	 * @param o1 题目
	 * @param o2 用户
	 * @return
	 */
	public Collecttopic selectId(int o1, int o2) {
		QueryWrapper<Collecttopic> queryWrapper = new QueryWrapper<Collecttopic>();
		queryWrapper.lambda().eq(Collecttopic::getTid, o1).eq(Collecttopic::getUid, o2);
		return dao.selectOne(queryWrapper);
	}
	
	/**
	 * 添加信息
	 * @param course
	 * @return
	 */
	public int add(Collecttopic object) {
		return dao.insert(object);
	}
	
	/**
	 * 查询信息
	 * @param id
	 * @return
	 */
	public Collecttopic selectOnt(int id) {
		return dao.selectById(id);
	}
	
	/**
	 * 修改信息
	 * @param user
	 * @return
	 */
	public int modification(Collecttopic object) {
		return dao.updateById(object);
	}
	
	/**
	 * 删除信息
	 * @param id
	 * @return
	 */
	public int delete(int id) {
		return dao.deleteById(id);
	}
}
